package com.hgb.mall.mbg.mapper;

import com.hgb.mall.mbg.entity.PmsComment;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.BasicColumn;
import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter;
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider;
import org.mybatis.dynamic.sql.select.CountDSLCompleter;
import org.mybatis.dynamic.sql.select.SelectDSLCompleter;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.UpdateDSLCompleter;
import org.mybatis.dynamic.sql.update.UpdateModel;
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;

import javax.annotation.Generated;
import java.util.List;
import java.util.Optional;

import static com.hgb.mall.mbg.mapper.PmsCommentDynamicSqlSupport.*;
import static org.mybatis.dynamic.sql.SqlBuilder.isEqualTo;

@Mapper
public interface PmsCommentMapper {
    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    BasicColumn[] selectList = BasicColumn
            .columnList(id, productId, memberNickName, productName, star, memberIp, createTime, showStatus, productAttribute, collectCouont, readCount, pics, memberIcon, replayCount, content);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    static UpdateDSL<UpdateModel> updateAllColumns(PmsComment record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(productId).equalTo(record::getProductId)
                  .set(memberNickName).equalTo(record::getMemberNickName)
                  .set(productName).equalTo(record::getProductName)
                  .set(star).equalTo(record::getStar)
                  .set(memberIp).equalTo(record::getMemberIp)
                  .set(createTime).equalTo(record::getCreateTime)
                  .set(showStatus).equalTo(record::getShowStatus)
                  .set(productAttribute).equalTo(record::getProductAttribute)
                  .set(collectCouont).equalTo(record::getCollectCouont)
                  .set(readCount).equalTo(record::getReadCount)
                  .set(pics).equalTo(record::getPics)
                  .set(memberIcon).equalTo(record::getMemberIcon)
                  .set(replayCount).equalTo(record::getReplayCount)
                  .set(content).equalTo(record::getContent);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    static UpdateDSL<UpdateModel> updateSelectiveColumns(PmsComment record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(productId).equalToWhenPresent(record::getProductId)
                  .set(memberNickName).equalToWhenPresent(record::getMemberNickName)
                  .set(productName).equalToWhenPresent(record::getProductName)
                  .set(star).equalToWhenPresent(record::getStar)
                  .set(memberIp).equalToWhenPresent(record::getMemberIp)
                  .set(createTime).equalToWhenPresent(record::getCreateTime)
                  .set(showStatus).equalToWhenPresent(record::getShowStatus)
                  .set(productAttribute).equalToWhenPresent(record::getProductAttribute)
                  .set(collectCouont).equalToWhenPresent(record::getCollectCouont)
                  .set(readCount).equalToWhenPresent(record::getReadCount)
                  .set(pics).equalToWhenPresent(record::getPics)
                  .set(memberIcon).equalToWhenPresent(record::getMemberIcon)
                  .set(replayCount).equalToWhenPresent(record::getReplayCount)
                  .set(content).equalToWhenPresent(record::getContent);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type = SqlProviderAdapter.class, method = "select")
    long count(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @DeleteProvider(type = SqlProviderAdapter.class, method = "delete")
    int delete(DeleteStatementProvider deleteStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @InsertProvider(type = SqlProviderAdapter.class, method = "insert")
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "record.id", before = false, resultType = Long.class)
    int insert(InsertStatementProvider<PmsComment> insertStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type = SqlProviderAdapter.class, method = "select")
    @ResultMap("PmsCommentResult")
    Optional<PmsComment> selectOne(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type = SqlProviderAdapter.class, method = "select")
    @Results(id = "PmsCommentResult", value = {
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "product_id", property = "productId", jdbcType = JdbcType.BIGINT),
            @Result(column = "member_nick_name", property = "memberNickName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "product_name", property = "productName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "star", property = "star", jdbcType = JdbcType.INTEGER),
            @Result(column = "member_ip", property = "memberIp", jdbcType = JdbcType.VARCHAR),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "show_status", property = "showStatus", jdbcType = JdbcType.INTEGER),
            @Result(column = "product_attribute", property = "productAttribute", jdbcType = JdbcType.VARCHAR),
            @Result(column = "collect_couont", property = "collectCouont", jdbcType = JdbcType.INTEGER),
            @Result(column = "read_count", property = "readCount", jdbcType = JdbcType.INTEGER),
            @Result(column = "pics", property = "pics", jdbcType = JdbcType.VARCHAR),
            @Result(column = "member_icon", property = "memberIcon", jdbcType = JdbcType.VARCHAR),
            @Result(column = "replay_count", property = "replayCount", jdbcType = JdbcType.INTEGER),
            @Result(column = "content", property = "content", jdbcType = JdbcType.LONGVARCHAR)
    })
    List<PmsComment> selectMany(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @UpdateProvider(type = SqlProviderAdapter.class, method = "update")
    int update(UpdateStatementProvider updateStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default long count(CountDSLCompleter completer) {
        return MyBatis3Utils.countFrom(this::count, pmsComment, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int delete(DeleteDSLCompleter completer) {
        return MyBatis3Utils.deleteFrom(this::delete, pmsComment, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int deleteByPrimaryKey(Long id_) {
        return delete(c ->
                c.where(id, isEqualTo(id_))
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int insert(PmsComment record) {
        return MyBatis3Utils.insert(this::insert, record, pmsComment, c ->
                c.map(productId).toProperty("productId")
                 .map(memberNickName).toProperty("memberNickName")
                 .map(productName).toProperty("productName")
                 .map(star).toProperty("star")
                 .map(memberIp).toProperty("memberIp")
                 .map(createTime).toProperty("createTime")
                 .map(showStatus).toProperty("showStatus")
                 .map(productAttribute).toProperty("productAttribute")
                 .map(collectCouont).toProperty("collectCouont")
                 .map(readCount).toProperty("readCount")
                 .map(pics).toProperty("pics")
                 .map(memberIcon).toProperty("memberIcon")
                 .map(replayCount).toProperty("replayCount")
                 .map(content).toProperty("content")
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int insertSelective(PmsComment record) {
        return MyBatis3Utils.insert(this::insert, record, pmsComment, c ->
                c.map(productId).toPropertyWhenPresent("productId", record::getProductId)
                 .map(memberNickName).toPropertyWhenPresent("memberNickName", record::getMemberNickName)
                 .map(productName).toPropertyWhenPresent("productName", record::getProductName)
                 .map(star).toPropertyWhenPresent("star", record::getStar)
                 .map(memberIp).toPropertyWhenPresent("memberIp", record::getMemberIp)
                 .map(createTime).toPropertyWhenPresent("createTime", record::getCreateTime)
                 .map(showStatus).toPropertyWhenPresent("showStatus", record::getShowStatus)
                 .map(productAttribute).toPropertyWhenPresent("productAttribute", record::getProductAttribute)
                 .map(collectCouont).toPropertyWhenPresent("collectCouont", record::getCollectCouont)
                 .map(readCount).toPropertyWhenPresent("readCount", record::getReadCount)
                 .map(pics).toPropertyWhenPresent("pics", record::getPics)
                 .map(memberIcon).toPropertyWhenPresent("memberIcon", record::getMemberIcon)
                 .map(replayCount).toPropertyWhenPresent("replayCount", record::getReplayCount)
                 .map(content).toPropertyWhenPresent("content", record::getContent)
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default Optional<PmsComment> selectOne(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectOne(this::selectOne, selectList, pmsComment, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default List<PmsComment> select(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectList(this::selectMany, selectList, pmsComment, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default List<PmsComment> selectDistinct(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectDistinct(this::selectMany, selectList, pmsComment, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default Optional<PmsComment> selectByPrimaryKey(Long id_) {
        return selectOne(c ->
                c.where(id, isEqualTo(id_))
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int update(UpdateDSLCompleter completer) {
        return MyBatis3Utils.update(this::update, pmsComment, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int updateByPrimaryKey(PmsComment record) {
        return update(c ->
                c.set(productId).equalTo(record::getProductId)
                 .set(memberNickName).equalTo(record::getMemberNickName)
                 .set(productName).equalTo(record::getProductName)
                 .set(star).equalTo(record::getStar)
                 .set(memberIp).equalTo(record::getMemberIp)
                 .set(createTime).equalTo(record::getCreateTime)
                 .set(showStatus).equalTo(record::getShowStatus)
                 .set(productAttribute).equalTo(record::getProductAttribute)
                 .set(collectCouont).equalTo(record::getCollectCouont)
                 .set(readCount).equalTo(record::getReadCount)
                 .set(pics).equalTo(record::getPics)
                 .set(memberIcon).equalTo(record::getMemberIcon)
                 .set(replayCount).equalTo(record::getReplayCount)
                 .set(content).equalTo(record::getContent)
                 .where(id, isEqualTo(record::getId))
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int updateByPrimaryKeySelective(PmsComment record) {
        return update(c ->
                c.set(productId).equalToWhenPresent(record::getProductId)
                 .set(memberNickName).equalToWhenPresent(record::getMemberNickName)
                 .set(productName).equalToWhenPresent(record::getProductName)
                 .set(star).equalToWhenPresent(record::getStar)
                 .set(memberIp).equalToWhenPresent(record::getMemberIp)
                 .set(createTime).equalToWhenPresent(record::getCreateTime)
                 .set(showStatus).equalToWhenPresent(record::getShowStatus)
                 .set(productAttribute).equalToWhenPresent(record::getProductAttribute)
                 .set(collectCouont).equalToWhenPresent(record::getCollectCouont)
                 .set(readCount).equalToWhenPresent(record::getReadCount)
                 .set(pics).equalToWhenPresent(record::getPics)
                 .set(memberIcon).equalToWhenPresent(record::getMemberIcon)
                 .set(replayCount).equalToWhenPresent(record::getReplayCount)
                 .set(content).equalToWhenPresent(record::getContent)
                 .where(id, isEqualTo(record::getId))
        );
    }
}
